package com.krtech.wecard.module.sys.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.krtech.wecard.framework.ext.mybatis.UserDataPower;
import com.krtech.wecard.module.pub.entity.ApplicationManagement;
import com.krtech.wecard.module.sys.entity.SysUser;
import java.util.List;

import com.krtech.wecard.module.sys.pojo.SysUserVo;
import com.krtech.wecard.module.sys.pojo.UserDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;import org.apache.ibatis.annotations.Select;

@Mapper
public interface SysUserMapper extends BaseMapper<SysUser> {

    public Page<SysUserVo> pageComplexAll(@Param("page") Page<SysUser> page, @Param("userDto") UserDto userDto);

    int updateBatch(List<SysUser> list);

    int batchInsert(@Param("list") List<SysUser> list);

    /**
     * 根据用户id获取其下的数据权限
     *
     * @param userId
     * @return
     */
    @Select("select p.* from sys_power p" +
            "                   inner join sys_role_power rw on rw.power_id = p.menu_id" +
            "                   inner join sys_user_role ur on rw.role_id = ur.role_id" +
            "                   inner join sys_role r on r.role_id = ur.role_id" +
            "            where ur.user_id = #{userId} and r.role_type = 2")
    List<UserDataPower> getUserDataPowers(Long userId);

    @Select("select * from sys_user where  user_id = #{userId} for update")
    public int lockUser(Integer userId);

    @Select("select * from pub_application_management where id in (\n" +
            "\tselect fk_application_id from pub_classification_application_info where fk_classification_id in (\n" +
            "\t\tselect id from pub_classification_info where fk_pub_card_info_id = (\n" +
            "\t\t\tselect card_id from pub_card_identity_relation_info where identity_id = #{identityId} and del_flag = 0\n" +
            "\t\t) and del_flag = 0\n" +
            "\t) and del_flag = 0\n" +
            ") and `status` = 1")
    public List<ApplicationManagement> getApplicationListByCurrentUserIdentfify(Integer identityId);
}